Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate formatter from yapf to ruff #1688

Closed
wants to merge 3 commits into from

Conversation

simon-mo
Copy link
Collaborator

The code format style of the Python project has over year migrated to black. https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html

ruff is the tool are adopting for both the linter and formatter. ruff is significantly faster than black (see https://astral.sh/blog/the-ruff-formatter), which makes is order of magnitude faster than yapf.

It's best to review this PR by commit. 0a41f7d contains the only change needed. 05aa9e6 contains the resulting run of format.

After merging this and #1665, I will move the two commits in .git-blame-ignore-revs so git history is unchanged. https://github.blog/changelog/2022-03-24-ignore-commits-in-the-blame-view-beta/

@simon-mo
Copy link
Collaborator Author

After that I will post a comments to all PR concerning the change.


Action Required! We recently switch the formatter from yapf to ruff which should modernize the codebase. Your PR is affected. To prevent issues with merging your code, here's what you'll need to do:

  1. Install ruff
pip install ruff==0.1.5
  1. Format changed files with ruff
# Move to top-level directory.
cd $(git rev-parse --show-toplevel)
# Format changed files.
MERGEBASE="$(git merge-base upstream/master HEAD)"
if ! git diff --diff-filter=ACRM --quiet --exit-code "$MERGEBASE" -- '*.py' &>/dev/null; then
    git diff --name-only --diff-filter=ACRM "$MERGEBASE" -- '*.py' | xargs -P 5 \
        ruff format --respect-gitignore .
fi
  1. Commit your changes.
git add --all
git commit -m "Format Python code with ruff"
  1. Merge master into your branch.
git pull upstream main

Resolve merge conflicts (if necessary).

After running these steps, you'll have the updated format.sh.

Thank you!

@simon-mo
Copy link
Collaborator Author

Too late to do it :( This codebase is too big and too many in progress PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant